package com.yksj.healthtalk.ui.doctorstation;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.TextView;

import com.yksj.healthtalk.comm.BaseFragmentActivity;
import com.yksj.healthtalk.ui.R;

/**
 * 医生工作台我的客户
 * @author zhao
 *
 */
public class DoctorStationCustomerActivity extends BaseFragmentActivity implements OnClickListener{

	ExpandableListView mExpandListView;
	SalonExpandListAdapter mExpandListAdapter;
	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.doctor_station_expandlist_layout);
		
		initView();
	}
	
	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.title_back:
			onBackPressed();
			break;
			
		}
	}
	
	private void initView(){
		initTitle();
		titleLeftBtn.setOnClickListener(this);
		mExpandListView = (ExpandableListView)findViewById(android.R.id.list);
		mExpandListView.setAdapter(mExpandListAdapter = new SalonExpandListAdapter(this));
		titleTextV.setText("我的客户");
		
		for (int i = 0; i < mExpandListAdapter.getGroupCount(); i++) {
			mExpandListView.expandGroup(i);
		}
	}
	
	class SalonExpandListAdapter extends BaseExpandableListAdapter{
		final List<String> groupList = new ArrayList<String>();
		final List<List> childList = new ArrayList<List>();
		final LayoutInflater mInflater;
		
		public SalonExpandListAdapter(Context context){
			mInflater = LayoutInflater.from(context);
			groupList.add("我创建的");
			for (int i = 0; i < groupList.size(); i++) {
				List list = new ArrayList();
				list.add("1");
				list.add("1");
				list.add("1");
				list.add("1");
				list.add("1");
				list.add("1");
				list.add("1");
				list.add("1");
				childList.add(list);
			}
		}
		
		@Override
		public int getGroupCount() {
			// TODO Auto-generated method stub
			return groupList.size();
		}

		@Override
		public int getChildrenCount(int groupPosition) {
			// TODO Auto-generated method stub
			return childList.get(groupPosition).size();
		}

		@Override
		public Object getGroup(int groupPosition) {
			// TODO Auto-generated method stub
			return groupList.get(groupPosition);
		}

		@Override
		public Object getChild(int groupPosition, int childPosition) {
			// TODO Auto-generated method stub
			return childList.get(childPosition);
		}

		@Override
		public long getGroupId(int groupPosition) {
			// TODO Auto-generated method stub
			return groupPosition;
		}

		@Override
		public long getChildId(int groupPosition, int childPosition) {
			// TODO Auto-generated method stub
			return childPosition;
		}

		@Override
		public boolean hasStableIds() {
			return false;
		}

		@Override
		public View getGroupView(int groupPosition, boolean isExpanded,
				View convertView, ViewGroup parent) {
			TextView textView;
			if(convertView == null){
				convertView = mInflater.inflate(R.layout.doctor_station_expandlist_group_item,null);
				textView = (TextView)convertView.findViewById(R.id.group_txt);
				convertView.setTag(textView);
			}else{
				textView = (TextView)convertView.getTag();
			}
			
			textView.setText("我的客户("+childList.get(groupPosition).size()+")");
			return convertView;
		}

		@Override
		public View getChildView(int groupPosition, int childPosition,
				boolean isLastChild, View convertView, ViewGroup parent) {
			ViewHolde holde;
			if(convertView == null){
				holde = new ViewHolde();
				convertView = mInflater.inflate(R.layout.doctor_station_expandlist_item,null);
				convertView.setTag(holde);
				
				holde.headerImageV = (ImageView)convertView.findViewById(R.id.header);
				holde.nameTextV = (TextView)convertView.findViewById(R.id.name);
				holde.detailTextV = (TextView)convertView.findViewById(R.id.detail_text);
//				holde.sizeTextV = (TextView)convertView.findViewById(R.id.size_txt);
			}else{
				holde = (ViewHolde)convertView.getTag();
			}
			
			holde.nameTextV.setText("我的客户"+childPosition);
			holde.detailTextV.setText("客户介绍"+childPosition);
//			holde.sizeTextV.setText(String.valueOf(childPosition));
			return convertView;
		}

		@Override
		public boolean isChildSelectable(int groupPosition, int childPosition) {
			return false;
		}
	}

	private static class ViewHolde{
		ImageView headerImageV;
		TextView sizeTextV;
		TextView nameTextV;
		TextView detailTextV;
	}
}
